/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Helpers;

import Hibernate.HibernateUtil;
import Entities.ContentDetail;
import java.util.List;
import org.hibernate.*;

/**
 *
 * @author Erhan
 */
public class ContentDetailHelper {

    Session session = null;

    /**
     *
     */
    public ContentDetailHelper() {
        this.session = HibernateUtil.getSessionFactory().getCurrentSession();
    }

    //Ophalen alles
    /**
     *
     * @return
     */
    public List<ContentDetail> getcontentDetailsen() {
        List<ContentDetail> contentDetailsenList = null;
        try {
            org.hibernate.Transaction tx = session.beginTransaction();
            Query q = session.createQuery("from ContentDetail");
            contentDetailsenList = (List<ContentDetail>) q.list();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return contentDetailsenList;
    }

    //Ophalen van 1
    /**
     *
     * @param id
     * @return
     */
    public ContentDetail getCursus(int id) {
        ContentDetail result = null;
        try {
            org.hibernate.Transaction tx = session.beginTransaction();
            Query q = session.createQuery("from content_detail where id=" + id);
            result = (ContentDetail) q.list().get(0);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return result;
    }


    // Wegschrijven
    /**
     *
     * @param contentDetail
     */
    public void persistCursus(ContentDetail contentDetail) {
        org.hibernate.Transaction tx = session.beginTransaction();
        tx.begin();
        session.persist(contentDetail);
        tx.commit();
    }

    // Verwijderen
    /**
     *
     * @param contentDetail
     */
    public void deleteCursus(ContentDetail contentDetail) {
        org.hibernate.Transaction tx = session.beginTransaction();
        tx.begin();
        session.delete(contentDetail);
        tx.commit();
    }

    // Updaten
    /**
     *
     * @param contentDetail
     */
    public void updateCursus(ContentDetail contentDetail) {
        org.hibernate.Transaction tx = session.beginTransaction();
        tx.begin();
        session.update(contentDetail);
        tx.commit();
    }
}